<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增科室调整记录')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-dept-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">员工姓名：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="userId" type="hidden" th:value="${user.id}" />
                        <input class="form-control" type="text" onclick="selectUserTree()" id="treeName" readonly="true" required th:value="${user.name}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">原科室：</label>
                <div class="col-sm-8">
                    <input name="oldId" type="hidden" id="oldId"/>
                    <div class="input-group">
                        <input name="oldName" onclick="selectOldTree()" id="oldName" type="text" placeholder="请选择原科室" readonly="true" required class="form-control">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">调整科室：</label>
                <div class="col-sm-8">
                    <input name="deptId" type="hidden" id="deptId"/>
                    <div class="input-group">
                        <input name="deptName" onclick="selectDeptTree()" id="deptName" type="text" placeholder="请选择调整科室" readonly="true" required class="form-control">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">调整时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="changeTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否默认：</label>
                <div class="col-sm-8">
                    <select name="isDefault" class="form-control m-b" th:with="type=${@dict.getType('sys_yes_no')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "record/dept"
        $("#form-dept-add").validate({
            focusCleanup: true
        });

        /* 选择人员 */
        function selectUserTree() {
            var options = {
                title: '选择员工',
                width: "380",
                url: ctx + "basic/user/selectTree",
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            var treeType = body.find('#treeType').val();
            if(treeType == 'user'){
                var id = body.find('#treeId').val();
                var treeId = id.substring(id.indexOf('_') + 1, id.length);
                $("#treeId").val(treeId);
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }else{
                $.modal.alertError("请选择员工");
            }
        }

        /* 选择部门树 */
        function selectOldTree() {
            var url = ctx + "system/dept/selectDeptTree/100";
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: oldSubmit
            };
            $.modal.openOptions(options);
        }

        function oldSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#oldId").val(body.find('#treeId').val());
            $("#oldName").val(body.find('#treeName').val());
            layer.close(index);
        }

        /* 用户管理-新增-选择部门树 */
        function selectDeptTree() {
            var url = ctx + "system/dept/selectDeptTree/100";
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit1
            };
            $.modal.openOptions(options);
        }

        function doSubmit1(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#deptId").val(body.find('#treeId').val());
            $("#deptName").val(body.find('#treeName').val());
            layer.close(index);
        }

        $("input[name='changeTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-dept-add').serialize());
            }
        }
    </script>
</body>
</html>